
import { reqUserMeInfo } from "@/api/user";

// state：仓库存储数据的地方
const state = {
    userInfo: {},
    roleList: [],
    activeCache: {}
}
// mutations：修改state的唯一手段，因此第一个参数必须是state，第二个参数为将要修改的数据
const mutations = {
    SET_USERINFO(state, res) {
        state.roleList = res.roleList;
        state.userInfo = res;
    },
    SVAE_ACTIVEMAP(state, res) {
        state.activeCache[res.uid] = res.activeStatus;
    },
    CLEAR_USERINFO(state){
        state.roleList = [];
        state.userInfo = {};
    }
}
// action：书写业务逻辑（method方法）
const actions = {
    setUserInfo({ commit }, res) {
        commit('SET_USERINFO', res);
    },
    clearUserInfo({ commit }){
        commit('CLEAR_USERINFO');
    },
    refreshUserInfo({ commit }) {
        reqUserMeInfo().then(res => {
            this.setUserInfo(commit, res.data);
        }).catch(error => {

        })
    }


}
// getters：计算属性
const getters = {

}

export default {
    state,
    mutations,
    actions,
    getters
}